//
//  File.swift
//  unique_ios_device_id
//
//  Created by Daniel on 2023/3/15.
//

import Foundation
import KeychainAccess

struct UUIDTool{

    static let IMEI_KEY:String = "IMEI"
    
    static func getUUID(_ keychainService: String) -> String {
        let keychain = Keychain(service: keychainService)
        var uuid:String = ""
        do {
            uuid = try keychain.get(IMEI_KEY) ?? ""
        }
        catch let error {
            print("error when get from kechain:\(error)")
        }
        if uuid.isEmpty {
            uuid = UUID().uuidString
            do {
                try keychain.set(uuid, key: IMEI_KEY)
            }
            catch let error {
                print("error when set kechain:\(error)")
                uuid = ""
            }
        }
        return uuid
    }
    
}
